package soccerBet.project.dao;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import soccerBet.project.objects.*;
import soccerBet.project.utils.*;

public class ApostasDAO {


	public Apostas getAposta(Integer idAposta) {

		Session session = HibernateUtil.getSessionFactory().openSession();
		
		Apostas aposta = (Apostas)  session.
		createQuery("select a from Apostas as a where a.idAposta = ?").setInteger(0, idAposta).uniqueResult();
		
		
		session.close();
		
		return aposta;

	}
	
	
	public Apostas getApostaBySID(String sid) {

		Session session = HibernateUtil.getSessionFactory().openSession();
		
		Apostas aposta = (Apostas)  session.
		createQuery("select a from Apostas as a where a.apostaSid = ?").setString(0, sid).uniqueResult();
		
		
		session.close();
		
		return aposta;

	}
	
	public List<Apostas> getApostasByMercado(Integer idMercado) {

		Session session = HibernateUtil.getSessionFactory().openSession();
		
		List<Apostas> apostasList = (List<Apostas>)  session.
		createQuery("select a from Apostas as a join a.mercados as m where m.idMercado = ? order by a.ordem asc").setInteger(0, idMercado).list();
		
		
		session.close();
		
		return apostasList;

	}



}